﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {
    public class TestSystemExtensions {
        [Fact]
        public void TestClamp () {
            var clamped1 = 0.5f.Clamp (1.0f, 2.0f);
            Assert.Equal(1.0f, clamped1);

            var clamped2 = 2.5f.Clamp (1.0f, 2.0f);
            Assert.Equal (2.0f, clamped2);
        }

        [Fact]
        public void TestLastIndexOf () {
            var array = new int[] { 1, 2, 3, 3, 4 };

            Assert.Equal (3, array.LastIndexOf (x => x == 3));
        }

        [Fact]
        public void TestExsists () {
            var array = new int[] { 1, 2, 3, 3, 4 };
            
            Assert.Equal (true, array.Exists (x => x == 3));
            Assert.Equal(false, array.Exists (x => x == 99));

        }

        [Fact]
        public void TestNormalize3 () {
            var vector   = new float[] { 1, 2, 3 };
            var expected = new float[] { 0.2672612f, 0.5345225f, 0.8017837f };

            Assert.Equal (expected, vector.Normalize(), new FloatComparere (0.00001f));
            Assert.Equal (expected, vector, new FloatComparere (0.00001f));
        }

 
        [Fact]
        public void TestNorm3 () {
            var vector = new float[] { 1, 2, 3 };

            Assert.Equal (3.741657f, vector.Norm (), new FloatComparere(0.00001f));
        }

        [Fact]
        public void TestDividedByW () {
            var vector   = new float[] { 2, 4, 6, 2 };
            var expected = new float[] { 1, 2, 3, 1 };

            Assert.Equal (expected, vector.DividedByW ());
            Assert.Equal (expected, vector);
        }

        [Fact]
        public void TestLookTo3 () {
            var pos1 = new float[] { 1, 1, 1 };
            var pos2 = new float[] { 5, 5, 5 };
            var expected = new float[] { 0.5773503f, 0.5773503f, 0.5773503f };

            Assert.Equal (expected, pos1.LookTo (pos2), new FloatComparere(0.00001f));
        }
    }
}
